function useFlagFormatter(value, row) {
    if (row.useFlag == 1) {
        return ' <span class="text-success">发布 </span>';
    } else {
        return ' <span class="text-warning">停用 </span>';
    }
}
// 加载table 数据
$(function(){
    $("#dataTable").bootstrapTable({ 
    	url: JSSYSMANAGERV1 + "/tlzsMessage/list.json",
    	method:"get", 
    	pagination:true,
    	sidePagination:"server",
    	queryParams: function(params) {
            return $.extend({}, params, parseJson(decodeURIComponent($("#dataForm").serialize())));     
        }
   }); 
 })

function buttonFormatter(value, row, index) {
	/* if (row.delFlag == 0) {
		var caozuo1 = "<button id='btn_edit' type='button' onclick='deleteEmp("+row.rowId+","+row.useFlag+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>&nbsp;删&nbsp;除&nbsp;</button>";
	} */
	var caozuo2 = "<button id='btn_edit' type='button' onclick='_update("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>修 改</button>";
	if (row.useFlag == 0) { //未发布
	     caozuo1 = "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.useFlag+", \""+row.messageTitle+"\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-ok'></span>发布</button>";
	} else { // 已发布
		caozuo1 = "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.useFlag+", \""+row.messageTitle+"\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-stop'></span>停用</button>";
	}
    return caozuo1+caozuo2;
}
// 弹出添加的窗口
function add(){
	layer.open({
 	  	type: 2,
	 	title: "添加消息",
 	  	closeBtn: 1,
 	  	shadeClose: true,
 	  	area: ['800px', '600px'],
 	  	content: JSSYSMANAGERV1 + '/tlzsMessage/toAddMessage',
 	  	btn: ["确 认","关 闭"], 
 	  	yes: function(index, layero){
	    	var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
	        iframeWin.add();
		}
	});
}
// 弹出添加的窗口      修改功能
function _update(rowId){
	layer.open({
 	  	type: 2,
 	  	title: "修改消息",
 	  	closeBtn: 1,
 	  	shadeClose: true,
 	  	area: ['800px', '600px'],
 	  	content: JSSYSMANAGERV1 + '/tlzsMessage/toAddMessage?rowId='+rowId,
 	  	btn: ["确 认","关 闭"], 
 	  	yes: function(index, layero){
	    	var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
	        iframeWin.add();
		}
	});
}
//删除消息
function deleteEmp(rowId, useFlag){
	var descStr = "【删除】";
	layer.confirm('您确认'+descStr+'?', {
		btn: ['确认', '取消']  
	},
	function(){
		var url = JSSYSMANAGERV1 + "/tlzsMessage/deleteMessage?rowId="+rowId+"&useFlag="+useFlag;
    	$.post(url,null,function(data){
  		    if (data == 1) { 
  		   		layer.alert(descStr+"成功", {icon: 1});
  		   		findData();
  		   	} else if (data == 2) {
  		   		layer.alert(descStr+"失败,该消息已发布");
  		   	} else {
  				layer.alert(descStr+"失败", {icon: 5});
  			}
		});
	},
	function(){ 
		return;
	});
}
//  发布/停用
function _stop(rowId, useFlag, messageTitle){
	var descStr = "【停用】<a style='color:red'>"+'"'+messageTitle+'"'+'</a>';
	if (useFlag == 0) {
		descStr = "【发布】<a style='color:red'>"+'"'+messageTitle+'"'+'</a>';
	}
	layer.confirm('您确认'+descStr+'消息吗？', {
		btn: ['确认', '取消']  
	}, 
	function(){
		if (rowId == null || rowId == "") {
    		layer.msg("id不能为空!");
    		return;
    	}
    	$.post(JSSYSMANAGERV1 + "/tlzsMessage/stop?rowId="+rowId+"&useFlag="+useFlag,null,function(json){
  		    if (json == 1) { 
  		        layer.alert(descStr+"成功", {icon: 1});
  		  		findData();
  			} else {
  				layer.alert(descStr+"失败", {icon: 5});
  			}
 	 	});
	},
	function(){
	   return;
	});
}
//查询
function findData(){
	$("#dataTable").bootstrapTable("refresh",{} ); 
}

/*bootstrap table点击行事件*/
$(function(){
	 $("body").on("click","table>tbody>tr",function(){
      $(this).css("background","#e1ecf1").siblings().css("background","");
   });
})

function deviceFormatter(value, row, index) {
	var gameId =  row.gameId; 
	var i = "";
	if(gameId == 10){
		i = "ios";
	}else if(gameId == 20){
		i = "android";
	}else{
		i = "全部";
	}
	return i;
}
function gameNameFormatter(value, row, index) {
	var gameName  = row.gameName;
	var i = "";
	if(gameName == 'TLYYS'){
		i = "体力阴阳师";
	}else if(gameName == 'SYDDLJ'){
		i = "代点链接";
	}else if(gameName == 'NLSC'){
		i = "能量商城";
	}else if(gameName == 'QQBBTZS'){
		i = "球球助手";
	}else{
		i = "全部";
	}
	return i;
}